package com.example.club

import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.club.R
import com.example.club.databinding.ActivityCarBinding
import com.therouter.router.Route
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.club.adapter.CarActivityAdapter
import com.example.club.model.CarActivityItem

@Route(path = "club/CarActivity")
class CarActivity : AppCompatActivity() {
    private lateinit var indicatorAll: View
    private lateinit var indicatorRecommend: View
    private lateinit var indicatorHot: View
    private lateinit var indicatorNearby: View
    private lateinit var tabAll: TextView
    private lateinit var tabRecommend: TextView
    private lateinit var tabHot: TextView
    private lateinit var tabNearby: TextView
    private lateinit var binding :ActivityCarBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_car)

            binding = ActivityCarBinding.inflate(layoutInflater)
        setContentView(binding.root)
        indicatorAll = findViewById(R.id.indicator_all)
        indicatorRecommend = findViewById(R.id.indicator_recommend)
        indicatorHot = findViewById(R.id.indicator_hot)
        indicatorNearby = findViewById(R.id.indicator_nearby)
        tabAll = findViewById(R.id.tab_all)
        tabRecommend = findViewById(R.id.tab_recommend)
        tabHot = findViewById(R.id.tab_hot)
        tabNearby = findViewById(R.id.tab_nearby)

        updateIndicator(0)

        tabAll.setOnClickListener { updateIndicator(0) }
        tabRecommend.setOnClickListener { updateIndicator(1) }
        tabHot.setOnClickListener { updateIndicator(2) }
        tabNearby.setOnClickListener { updateIndicator(3) }

        binding.ivBack.setOnClickListener {
            finish()
        }

        // 新增：RecyclerView数据源和适配器
        val activityList = listOf(
            CarActivityItem(
                R.drawable.car6,
                "俱乐部活动1",
                isOfficial = true,
                isHot = true,
                status = "活动进行中",
                signupCount = 12,
                time = "2023.03.02~2023.04.05",
                distance = "<100m"
            ),
            CarActivityItem(
                R.drawable.car6,
                "俱乐部活动2",
                isOfficial = false,
                isHot = true,
                status = "活动进行中",
                signupCount = 8,
                time = "2023.04.10~2023.04.20",
                distance = "<500m"
            ),
            CarActivityItem(
                R.drawable.car6,
                "俱乐部活动3",
                isOfficial = true,
                isHot = false,
                status = "活动进行中",
                signupCount = 20,
                time = "2023.05.01~2023.05.10",
                distance = "<1km"
            ),
            CarActivityItem(
                R.drawable.car6,
                "俱乐部活动3",
                isOfficial = true,
                isHot = false,
                status = "活动进行中",
                signupCount = 20,
                time = "2023.05.01~2023.05.10",
                distance = "<1km"
            )
            ,
            CarActivityItem(
                R.drawable.car6,
                "俱乐部活动3",
                isOfficial = true,
                isHot = false,
                status = "活动进行中",
                signupCount = 20,
                time = "2023.05.01~2023.05.10",
                distance = "<1km"
            ),
            CarActivityItem(
                R.drawable.car6,
                "俱乐部活动3",
                isOfficial = true,
                isHot = false,
                status = "活动进行中",
                signupCount = 20,
                time = "2023.05.01~2023.05.10",
                distance = "<1km"
            )
        )
        val adapter = CarActivityAdapter(activityList)
        binding.activityRecycler.layoutManager = LinearLayoutManager(this)
        binding.activityRecycler.adapter = adapter
    }

    private fun updateIndicator(index: Int) {
        indicatorAll.visibility = if (index == 0) View.VISIBLE else View.GONE
        indicatorRecommend.visibility = if (index == 1) View.VISIBLE else View.GONE
        indicatorHot.visibility = if (index == 2) View.VISIBLE else View.GONE
        indicatorNearby.visibility = if (index == 3) View.VISIBLE else View.GONE

        val colorRed = 0xFFE60012.toInt()
        val colorGray = 0xFF888888.toInt()
        tabAll.setTextColor(if (index == 0) colorRed else colorGray)
        tabRecommend.setTextColor(if (index == 1) colorRed else colorGray)
        tabHot.setTextColor(if (index == 2) colorRed else colorGray)
        tabNearby.setTextColor(if (index == 3) colorRed else colorGray)
    }

}